package com.jxw.launcher.util;

import android.content.Context;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/* loaded from: classes.dex */
public class UnzipAssets {
    public static void unZip(Context context, String str, String str2, boolean z) throws IOException {
        File file = new File(str2);
        if (!file.exists()) {
            file.mkdirs();
        }
        ZipInputStream zipInputStream = new ZipInputStream(context.getAssets().open(str));
        byte[] bArr = new byte[2097152];
        for (ZipEntry nextEntry = zipInputStream.getNextEntry(); nextEntry != null; nextEntry = zipInputStream.getNextEntry()) {
            if (nextEntry.isDirectory()) {
                File file2 = new File(str2 + File.separator + nextEntry.getName());
                if (z || !file2.exists()) {
                    file2.mkdir();
                }
            } else {
                File file3 = new File(str2 + File.separator + nextEntry.getName());
                if (z || !file3.exists()) {
                    file3.createNewFile();
                    FileOutputStream fileOutputStream = new FileOutputStream(file3);
                    while (true) {
                        int read = zipInputStream.read(bArr);
                        if (read <= 0) {
                            break;
                        }
                        fileOutputStream.write(bArr, 0, read);
                    }
                    fileOutputStream.close();
                }
            }
        }
        zipInputStream.close();
    }
}
